package org.example.struct.array2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author liyishan
 * @date 2024/9/4 10:01
 * @apiNote
 */

public class Test02860CountWays {
    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>();
        nums.add(1);
        nums.add(2);
        nums.add(3);
        nums.add(4);
        nums.add(5);
        System.out.println(countWays(nums));
    }
    public static int countWays(List<Integer> nums) {
        int n = nums.size();
        int res = 0;
        Collections.sort(nums);
        for (int i = 0; i <= n; i++) {
            if(i > 0 && nums.get(i-1)>= i){
                continue;
            }
            if(i < n && nums.get(i) <= i){
                continue;
            }
            res++;
        }
        return res;
    }
}
